<?php
/**
 * @package wolly_stats
 * @author Paolo Valenti
 * @version 1.0 primo rilascio
 */
/*
Plugin Name: wollystats
Plugin URI: http://www.paolo.valenti.name
Description: Questo plugin vi stampa delle statistiche del vostro blog
Author: Paolo Valenti
Version: 1.0
Author URI: http://www.paolo.valenti.name
*/
// creiamo la funzione
function wolly_totpost06() {
global $wpdb;
// Estraiamo i dati del 2008 dal database
$tot_post08 = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_date >= '2008-01-01' AND post_date < '2009-01-01' AND post_status = 'publish'");
$totcomments08 = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_date >= '2008-01-01' AND comment_date < '2009-01-01' AND comment_approved = '1' ");
$avgpostlen08 = ceil($wpdb->get_var("SELECT AVG(LENGTH(post_content)) FROM $wpdb->posts WHERE post_date >= '2008-01-01' AND post_date < '2009-01-01' AND post_status = 'publish' "));
$totpostlen08 = $wpdb->get_var("SELECT SUM(LENGTH(post_content)) FROM $wpdb->posts WHERE post_date >= '2008-01-01' AND post_date < '2009-01-01' AND post_status = 'publish' ");
$avgcomments08 = ceil($totcomments08/$tot_post08);
// Estraiamo i dati del 2007 dal database
$tot_post07 = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_date >= '2007-01-01' AND post_date < '2008-01-01' AND post_status = 'publish'");
$totcomments07 = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_date >= '2007-01-01' AND comment_date < '2008-01-01' AND comment_approved = '1' ");
$avgpostlen07 = ceil($wpdb->get_var("SELECT AVG(LENGTH(post_content)) FROM $wpdb->posts WHERE post_date >= '2007-01-01' AND post_date < '2008-01-01' AND post_status = 'publish' "));
$totpostlen07 = $wpdb->get_var("SELECT SUM(LENGTH(post_content)) FROM $wpdb->posts WHERE post_date >= '2007-01-01' AND post_date < '2008-01-01' AND post_status = 'publish' ");
$avgcomments07 = ceil($totcomments07/$tot_post07);
// Estraiamo i dati del 2006 dal database
$tot_post06 = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_date >= '2006-01-01' AND post_date < '2007-01-01' AND post_status = 'publish'");
$totcomments06 = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_date >= '2006-01-01' AND comment_date < '2007-01-01' AND comment_approved = '1' ");
$avgpostlen06 = ceil($wpdb->get_var("SELECT AVG(LENGTH(post_content)) FROM $wpdb->posts WHERE post_date >= '2006-01-01' AND post_date < '2007-01-01' AND post_status = 'publish' "));
$totpostlen06 = $wpdb->get_var("SELECT SUM(LENGTH(post_content)) FROM $wpdb->posts WHERE post_date >= '2006-01-01' AND post_date < '2007-01-01' AND post_status = 'publish' ");
$avgcomments06 = ceil($totcomments06/$tot_post06);
// Estraiamo i dati del 2005 dal database
$tot_post05 = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_date >= '2005-01-01' AND post_date < '2006-01-01' AND post_status = 'publish'");
$totcomments05 = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_date >= '2005-01-01' AND comment_date < '2006-01-01' AND comment_approved = '1' ");
$avgpostlen05 = ceil($wpdb->get_var("SELECT AVG(LENGTH(post_content)) FROM $wpdb->posts WHERE post_date >= '2005-01-01' AND post_date < '2006-01-01' AND post_status = 'publish' "));
$totpostlen05 = $wpdb->get_var("SELECT SUM(LENGTH(post_content)) FROM $wpdb->posts WHERE post_date >= '2005-01-01' AND post_date < '2006-01-01' AND post_status = 'publish' ");
$avgcomments05 = ceil($totcomments05/$tot_post05);
// Estraiamo i dati del 2004 dal database
$tot_post04 = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_date >= '2004-01-01' AND post_date < '2005-01-01' AND post_status = 'publish'");
$totcomments04 = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_date >= '2004-01-01' AND comment_date < '2005-01-01' AND comment_approved = '1' ");
$avgpostlen04 = ceil($wpdb->get_var("SELECT AVG(LENGTH(post_content)) FROM $wpdb->posts WHERE post_date >= '2004-01-01' AND post_date < '2005-01-01' AND post_status = 'publish' "));
$totpostlen04 = $wpdb->get_var("SELECT SUM(LENGTH(post_content)) FROM $wpdb->posts WHERE post_date >= '2004-01-01' AND post_date < '2005-01-01' AND post_status = 'publish' ");
$avgcomments04 = ceil($totcomments04/$tot_post04);
// Estraiamo i dati del 2003 dal database
$tot_post03 = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_date >= '2003-01-01' AND post_date < '2004-01-01' AND post_status = 'publish'");
$totcomments03 = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_date >= '2003-01-01' AND comment_date < '2004-01-01' AND comment_approved = '1' ");
$avgpostlen03 = ceil($wpdb->get_var("SELECT AVG(LENGTH(post_content)) FROM $wpdb->posts WHERE post_date >= '2003-01-01' AND post_date < '2004-01-01' AND post_status = 'publish' "));
$totpostlen03 = $wpdb->get_var("SELECT SUM(LENGTH(post_content)) FROM $wpdb->posts WHERE post_date >= '2003-01-01' AND post_date < '2004-01-01' AND post_status = 'publish' ");
$avgcomments03 = ceil($totcomments03/$tot_post03);
//definiamo la tabella e l'intestazione della tabella
echo '<table cellspacing="10">';
echo '<tr>';
echo '<th width="50">';
echo '</th>';
echo '<th>';
echo 'Post';
echo '</th>';
echo '<th>';
echo 'Media caratteri';
echo '</th>';
echo '<th>';
echo 'Caratteri Totali';
echo '</th>';
echo '<th>';
echo 'media Commenti';
echo '</th>';
echo '<th>';
echo 'Commenti Totali';
echo '</th>';
echo '</tr>';
//stampiamo i dati del 2008
echo '<tr>';
echo '<td>';
echo '2008';
echo '</td>';
echo "<td align='right'>";
echo $tot_post08;
echo '</td>';
echo "<td align='right'>";
echo $avgpostlen08;
echo '</td>';
echo "<td align='right'>";
echo $totpostlen08;
echo '</td>';
echo "<td align='right'>";
echo $avgcomments08;
echo '</td>';
echo "<td align='right'>";
echo $totcomments08;
echo '</td>';
echo '</tr>';
//stampiamo i dati del 2007
echo '<tr>';
echo '<td>';
echo '2007';
echo '</td>';
echo "<td align='right'>";
echo $tot_post07;
echo '</td>';
echo "<td align='right'>";
echo $avgpostlen07;
echo '</td>';
echo "<td align='right'>";
echo $totpostlen07;
echo '</td>';
echo "<td align='right'>";
echo $avgcomments07;
echo '</td>';
echo "<td align='right'>";
echo $totcomments07;
echo '</td>';
echo '</tr>';
//stampiamo i dati del 2006
echo '<tr>';
echo '<td>';
echo '2006';
echo '</td>';
echo "<td align='right'>";
echo $tot_post06;
echo '</td>';
echo "<td align='right'>";
echo $avgpostlen06;
echo '</td>';
echo "<td align='right'>";
echo $totpostlen06;
echo '</td>';
echo "<td align='right'>";
echo $avgcomments06;
echo '</td>';
echo "<td align='right'>";
echo $totcomments06;
echo '</td>';
echo '</tr>';
//stampiamo i dati del 2005
echo '<tr>';
echo '<td>';
echo '2005';
echo '</td>';
echo "<td align='right'>";
echo $tot_post05;
echo '</td>';
echo "<td align='right'>";
echo $avgpostlen05;
echo '</td>';
echo "<td align='right'>";
echo $totpostlen05;
echo '</td>';
echo "<td align='right'>";
echo $avgcomments05;
echo '</td>';
echo "<td align='right'>";
echo $totcomments05;
echo '</td>';
echo '</tr>';
//stampiamo i dati del 2004
echo '<tr>';
echo '<td>';
echo '2004';
echo '</td>';
echo "<td align='right'>";
echo $tot_post04;
echo '</td>';
echo "<td align='right'>";
echo $avgpostlen04;
echo '</td>';
echo "<td align='right'>";
echo $totpostlen04;
echo '</td>';
echo "<td align='right'>";
echo $avgcomments04;
echo '</td>';
echo "<td align='right'>";
echo $totcomments04;
echo '</td>';
echo '</tr>';
//stampiamo i dati del 2003
echo '<tr>';
echo '<td>';
echo '2003';
echo '</td>';
echo "<td align='right'>";
echo $tot_post03;
echo '</td>';
echo "<td align='right'>";
echo $avgpostlen03;
echo '</td>';
echo "<td align='right'>";
echo $totpostlen03;
echo '</td>';
echo "<td align='right'>";
echo $avgcomments03;
echo '</td>';
echo "<td align='right'>";
echo $totcomments03;
echo '</td>';
echo '</tr>';
// chiudiamo la tabella
echo '</table>';

}
// aggiungiamo lo shortcode da utilizzare nei post
function wollystats_shortcode() {
	wolly_totpost06();
}
add_shortcode('wollystats', 'wollystats_shortcode');


?>